package library.database.user;

import java.io.IOException;
import java.sql.ResultSet;
import java.sql.SQLException;

public class DatabaseReaderProxy extends DatabaseUserProxy {
	static DatabaseBookProxy bkproxy;
	public DatabaseReaderProxy() throws ClassNotFoundException, IOException, SQLException {
		super();
		bkproxy = new DatabaseBookProxy();
	}
	/**
	 * 展示架上未借出所有的书籍
	 * @throws SQLException
	 * todo
	 */
	public ResultSet showAllBooks() throws SQLException{
		ResultSet rs =bkproxy.showBooks();
		return rs;
	}
	/**
	 * 传入一个读者对象，返回读者借阅的全部书籍。
	 * @param user
	 * @return ResultSet
	 * @throws SQLException
	 */
	public ResultSet showBorrowedBooks(int id) throws SQLException{
		ResultSet rs = bkproxy.showMyborrow(id);
		return rs;
	}
	/**
	 * 展示一本已借阅的书籍
	 * @param userid
	 * @param bkid
	 * @return
	 * @throws SQLException
	 */
	public ResultSet showOneBrrowedBook(int userid, int bkid) throws SQLException{
		ResultSet rs = bkproxy.showSpecifiedBook(userid, bkid);
		return rs;
	
	}
	/**
	 * 还书操作
	 * @param userid
	 * @param bkid
	 * @return
	 * @throws SQLException
	 */
	public boolean returnBooks(int userid,int bkid) throws SQLException{
		return bkproxy.returnBooks(bkid,userid);
	}
	/**
	 * 检查该书是否存在
	 * @param bkid
	 * @return
	 * @throws SQLException
	 */
	public boolean checkbook(int bkid) throws SQLException
	{
		ResultSet rs = bkproxy.showBookbyId(bkid);
		if(rs.next()==false) return false;
		else return true;
	}
	/**
	 * 借阅书籍
	 * @param bkid
	 * @return
	 * @throws SQLException
	 */
	public boolean borrowbook(int bkid,int userid) throws SQLException
	{
		return bkproxy.borrowBooks(bkid, userid);
	}
	public int checkbooknum(int bkid) throws SQLException
	{
		return bkproxy.CheckNum(bkid);
	}

}